<?php

namespace App\Console\Commands;

use App\Models\Account;
use Illuminate\Console\Command;

class ClueYesterday extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'clue:yesterday';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '获取飞鱼 Clues.';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $accounts = Account::where('enable', true)->get();
        $accounts->each(function ($account) {
            $r = $account->yesterdayClue();

            if ($r['result']) {
                $this->info("{ $account->name} 获取数据成功,一共获取了 {$r['count']}条");
            } else {
                $this->warn("{$account->name}  获取失败");
            }
        });
    }
}
